#include "NfcApiBridgeSession.h"


EXPORT_C HBufC8 * RNfcApiBridgeSession::ReadTagL(TDesC8 const & aWidgetId, TDesC8 const & aTnf, TDesC8 const & aType, TInt aTimeout)
    {
    Api::ReadTagArgsType args(aWidgetId, aTnf, aType, aTimeout);
    Api::ReadTagRetType ret;
    CleanupClosePushL(args);
    CleanupClosePushL(ret);
    
    TRequestStatus status;
    iApi.iReadTagAsync.CallL(*this, args, status);
    User::WaitForRequest(status);
    iApi.iReadTagAsync.GetResult(*this, ret);
    
    HBufC8 * retBuf = ret.Data().AdoptL();
    CleanupStack::PopAndDestroy(2, &args);
    return retBuf;
    }

EXPORT_C void RNfcApiBridgeSession::SetForegroundL(TDesC8 const & aWidgetId, TBool aOnForeground)
    {
    Api::SetForegroudArgsType args(aWidgetId, aOnForeground);
    CleanupClosePushL(args);
    
    iApi.iSetForeground.CallL(*this, args);
    
    CleanupStack::PopAndDestroy(&args);
    }

EXPORT_C TInt RNfcApiBridgeSession::SendMessageL(TDesC8 const & aWidgetId, TDesC8 const & aMessageId, TDesC8 const & aContent, TInt aValidFor)
	{
	Api::SendMessageArgsType args(aWidgetId, aMessageId, aContent, aValidFor);
    Api::SendMessageRetType ret;
    CleanupClosePushL(args);
    CleanupClosePushL(ret);
    
	iApi.iSendMessage.CallL(*this, ret, args);
    TInt retVal = ret.Data();
	
	CleanupStack::PopAndDestroy(2, &args);
	return retVal;
	}

EXPORT_C TInt RNfcApiBridgeSession::SetResponseL(TDesC8 const & aWidgetId, TDesC8 const & aMessageId, TDesC8 const & aContent, TInt aValidFor)
	{
	Api::SetResponseArgsType args(aWidgetId, aMessageId, aContent, aValidFor);
	Api::SetResponseRetType ret;
	CleanupClosePushL(args);
	CleanupClosePushL(ret);
	
	iApi.iSetResponse.CallL(*this, ret, args);
    TInt retVal = ret.Data();
	
	CleanupStack::PopAndDestroy(2, &args);
	return retVal;
	}

EXPORT_C HBufC8 * RNfcApiBridgeSession::TransactionLogL(TDesC8 const & aWidgetId)
	{
	Api::TransactionLogArgsType args(aWidgetId);
	Api::TransactionLogRetType ret;
	CleanupClosePushL(args);
	CleanupClosePushL(ret);
	
	iApi.iTransactionLog.CallL(*this, ret, args);
	HBufC8 * retBuf = ret.Data().AdoptL();
	
	CleanupStack::PopAndDestroy(2, &args);
	return retBuf;
	}
